package com.king.eventbusdemo;

import android.app.Activity;
import android.os.Bundle;
import android.util.JsonReader;
import android.view.View;
import android.widget.TextView;

import com.king.eventbusdemo.entity.EventBusBean;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * @author: King
 * @project: EventBusDemo
 * @package: com.king.eventbusdemo
 * @date: 2019/3/25
 * @time: 15:34
 */
public class JSMessageActivity extends Activity {

    TextView tv_cone;
    @Override
    protected void onCreate( Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_js_message);

        initView();
    }

    private void initView() {
        tv_cone = findViewById(R.id.tv_cone);
    }

    public void getMess(View view){
        EventBus.getDefault().register(JSMessageActivity.this);
    }
    @Subscribe(threadMode = ThreadMode.MAIN,sticky = true)
    public void eventBuseMessage(EventBusBean eventBusBean){
        tv_cone.setText(eventBusBean.name+"---"+eventBusBean.pwd);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().removeAllStickyEvents();
        EventBus.getDefault().unregister(JSMessageActivity.this);
    }
}
